﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Acms.AcmsControls.ContentControls.FrontEnd;
using Acms.Bll;
//using System.Net.Mail;

namespace Ait.Web.Templates.Contact
{
    public partial class _default : Acms.AcmsControls.TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Click += new EventHandler(btnSubmit_Click);
        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            
            Validate();
            if (IsValid)
            {

                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

                //set the addresses
                //var toEmail= ddlSubject.SelectedValue;
                string toEmail = "customer.services@ait-pg.co.uk";
                //var toEmail;
                string subject= Convert.ToString(ddlSubject.SelectedItem);
                
                switch(subject){
                    case "Data Centre Management":
                        toEmail="customer.services@ait-pg.co.uk";
                        break;
                    case "Network Solutions":
                        toEmail="customer.services@ait-pg.co.uk";
                        break;
                        
                    case "Digital signage":
                        toEmail="customer.services@ait-pg.co.uk";
                        break;
                    
                    case "Returning a product":
                        toEmail="customer.services@ait-pg.co.uk";
                        break;

                    case "Technical support":
                        toEmail="customer.services@ait-pg.co.uk";
                        break;

                    case "Accounts":
                        toEmail="accounts@ait-pg.co.uk";
                        break;

                    case "Customer service":
                        toEmail="accounts@ait-pg.co.uk";
                        break;

                    case "Recruitment":
                        toEmail = "hr@ait-pg.co.uk";
                        break;
                    
                        
                }
                
                
                
                var toEmilName= ddlSubject.SelectedItem;
                mail.To.Add(new System.Net.Mail.MailAddress(toEmail));
                mail.Bcc.Add("acmsemail@gmail.com");
                //mail.To.Add(new System.Net.Mail.MailAddress("toma57@hotmail.com", "Moo Me"));

                mail.From = new System.Net.Mail.MailAddress(txtEmail.Text, txtName.Text);
                //mail.To.Add("you@yourcompany.com");

                //set the content
                mail.Subject = "AIT-PG Web Enquiry : " + ddlSubject.SelectedItem;

                mail.Body = string.Concat(
                    "Phone Number: ", txtPhone.Text, " \r\n ",
                    "Company: ", txtCompany.Text, " \r\n ",
                    "Email: ", txtEmail.Text, " \r\n ",
                    "Question: ", txtQuestion.Text
                    );
                
                


                try
                {
                    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                    client.Send(mail);
                    mail.Dispose();
                    pnlMessageSent.Visible = true;
                    pnlCreateMsg.Visible = false;
                }
                catch
                {
                    pnlCreateMsg.Visible = false;
                    pnlMessageError.Visible = true;

                }




            }
        }
    }
}
